home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacWorld: Complete Mac Interactive
/
Macworld Complete Mac Interactive CD)(1994).iso
/
The Best of BMUG
/
Utilities
/
Text and Speech
/
Alpha.5.76
/
Tcl
/
UserCode
/
reverseLines.tcl
< prev
next >
Wrap
Text File
|
1994-03-08
|
2KB
|
69 lines
# FILE: reverseLines.tcl
#
# LAST UPDATE: 01/06/93 5:23:08 AM
#
# This file contains the following TCL procedure(s):
#
# reverseLines -- Reverses the order a selection of lines of text
#
# To use, simply source this file place it in the a folder with the
# name $HOME:Tcl:Usercode: and invoke it implicitly via the "unknown proc".
#
# SEE ALSO unknown.tcl
# COPYRIGHT:
#
# Copyright © 1992,1993 by David C. Black
# All rights reserved.
#
# Redistribution and use in source and binary forms are permitted
# provided that the above copyright notice and this paragraph are
# duplicated in all such forms and that any documentation,
# advertising materials, and other materials related to such
# distribution and use acknowledge that the software was developed
# by David C. Black.
#
# THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
################################################################################
# AUTHOR
#
# David C. Black
# Internet: black@mpd.tandem.com (preferred)
# GEnie: D.C.Black
# USnail: 6217 John Chisum Lane, Austin, TX 78749
#
################################################################################
# HISTORY
#
# modified who rev reason
# -------- --- --- ------
# 01/06/93 DCB 1.0 Original
proc reverseLines {} {
set end [selEnd]
set start [getPos]
if {$start == $end} {
alertnote "You must highlight the section you wish to reverse."
return
}
if {[lookAt [expr $end-1]] != "\r"} {
alertnote "The selection must consist only of complete lines."
return
}
set text [split [getText $start [expr {$end-1}]] "\r"]
set i [llength $text]
while {$i > 0} {
incr i -1
lappend reversed [lindex $text $i]
}
#endwhile
set text [join $reversed "\r"]
replaceText $start [expr {$end-1}] $text
select $start $end
}